#include #include #include using namespace std; struct BibleVerse { string book; int chapter; int verse; string text; void display(ostream& out); }; void BibleVerse::display(ostream& out) { out << book << " " << chapter << ":" << verse << endl; } ostream& operator<< (ostream& out, BibleVerse& bibleVerse) { out << bibleVerse.book << " " << bibleVerse.chapter << ":" << bibleVerse.verse << endl; return out; } void main() { ifstream bible("bible.txt"); string line; BibleVerse currentBibleVerse; while(!bible.eof()) { getline(bible, line); if(line.length() == 0) { //for now, do nothing cout << currentBibleVerse << endl; //currentBibleVerse.display(cout); } else if(isdigit(line[0])) { currentBibleVerse.chapter = atoi(line.substr(0,3).c_str()); currentBibleVerse.verse = atoi(line.substr(4,3).c_str()); //read the text too } else if(line[0] == 'B') { currentBibleVerse.book = line.substr(8); //there is always a blank line after the new book, throw the blank line away getline(bible, line); } else if(line[0] == ' ') { //read more text here } } bible.close(); }